<template>
	<view style="background-color: #FFFFFF;">
		<view style="background-color: #FFFFFF;height: calc( 100vh - 280rpx); overflow-y: auto;padding-bottom: 40rpx;">
			<view class="tline" style="background-color: #F6FAFA;"></view>
			<view class="pl25 pr25">
				<view class="pt30 pb30 flex flex-ac flex-pj bb" @click="toRecord">
					<text style="font-size: 30rpx;">咨询人</text>
					<view class="flex flex-ac" v-if="personalFileId==0">
						<text class="ft12" style="font-size: 30rpx;color: #B0B0B0;">请选择咨询人</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>
					<view class="flex flex-ac" v-if="personalFileId!=0">
						<text class="ft12" style="font-size: 30rpx;">{{consultant}}</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>
				</view>
				<view class="pt30 pb30 flex flex-ac flex-pj bb" @click="toAddress">
					<text style="font-size: 30rpx;">地址</text>
					<view class="flex flex-ac" v-if="adressInfo==0">
						<text class="it1 ftc ft12" style="font-size: 30rpx;color: #B0B0B0;">我们会根据您的位置为你匹配药房</text>
						<text class="ft12" style="font-size: 30rpx;color: #B0B0B0;">请选择地址</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>

					<view class="flex flex-ac" v-if="adressInfo!=0">
						<text class="ft12" style="font-size: 30rpx;">{{adressInfo}}</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>

				</view>
				<view class="pt30 pb30 flex flex-ac flex-pj bb" @click="openaim">
					<text style="font-size: 30rpx;">问诊目的</text>
					<view class="flex flex-ac">
						<text v-if="aimkey==1" style="font-size: 30rpx;">在线复诊</text>
						<text v-else-if="aimkey==2" style="font-size: 30rpx;">复诊续方</text>
						<text v-else class="ft12" style="font-size: 30rpx;color: #B0B0B0;">请输入您的问诊目的</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>
				</view>
				<view class="pt30 pb30 flex flex-ac flex-pj bb" v-if="aimkey==1" @click="toMedcalRecords">
					<text style="font-size: 30rpx;">就诊记录</text>
					<view class="flex flex-ac" v-if="medcalRecords==0">
						<text class="ft12" style="font-size: 30rpx;color: #B0B0B0;">请选择需要复诊的就诊记录</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>
					<view class="flex flex-ac" v-if="medcalRecords!=0">
						<text class="ft12" style="font-size: 30rpx;">已选择就诊档案</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>
				</view>

				<view class="pt30 pb30 flex flex-ac flex-pj bb" v-if="aimkey==1">
					<text style="font-size: 30rpx;">首诊医院</text>
					<view class="flex flex-ac">
						<input class="uni-input" v-model="hspName" placeholder="首诊医院名称" />
					</view>
				</view>


				<view class="pt30 pb30 flex flex-ac flex-pj bb" v-if="aimkey==2" @click="toChufangRecords">
					<text style="font-size: 30rpx;">历史处方</text>
					<view class="flex flex-ac" v-if="chufangRecords==0">
						<text class="ft12" style="font-size: 30rpx;color: #B0B0B0;">请选择需要复诊的历史处方</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>
					<view class="flex flex-ac" v-if="chufangRecords!=0">
						<text class="ft12" style="font-size: 30rpx;">已选择历史处方</text>
						<image class="arrow ml15"
							src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/arrow.png">
						</image>
					</view>
				</view>
			</view>
			<view class="tline" style="background-color: #F6FAFA;"></view>
			<view class="pl25 pr25">
				<view class="pt30 pb30">症状描述</view>
				<textarea @input="setKeyword" class="block w100 pad20 box" maxlength="150"></textarea>
				<view class="pt30 pb30">患处照片<text class="ft12 c999"
						style="margin-left: 10rpx;">根据病情需要上传，系统加密仅医生可见</text></view>
				<view class="imgs pl10 pr10" style="align-items: center;flex-wrap: wrap;">
					<block v-for="(item,index) in Imgs" :key="index">
						<view style="position: relative;">
							<image :src="item" style="height: 186rpx;width: 186rpx;" mode="scaleToFill"></image>
							<image src="../static/imgs/xx.png" style="height: 42rpx;width: 42rpx;border-radius: 50%;
							position: absolute;top:-10rpx;right: -10rpx;" @click="delImg(item)"></image>
						</view>
					</block>
					<view v-if="Imgs.length<8" @click="uploadImg"
						style="width: 190rpx;height: 186rpx;background: #EDF6F5;border-radius: 8rpx;display: flex;flex-direction: column;align-items: center;justify-content: center;">
						<image src="../../static/images/pzp.png" style="width: 50%;" mode="widthFix"></image>
						<view>拍照</view>
					</view>
				</view>
				<view class="pt30 pb30">历史诊疗信息<text class="ft12 c999"
						style="margin-left: 10rpx;">其他医院病历、检验检查单拍照上传</text></view>
				<view class="imgs pl10 pr10" style="align-items: center;flex-wrap: wrap;">
					<block v-for="(item,index) in znImgs" :key="index">
						<view style="position: relative;">
							<image :src="item" style="height: 186rpx;width: 186rpx;" mode="scaleToFill"></image>
							<image src="../static/imgs/xx.png" style="height: 42rpx;width: 42rpx;border-radius: 50%;
							position: absolute;top:-10rpx;right: -10rpx;" @click="delZnImg(item)"></image>
						</view>
					</block>
					<view v-if="znImgs.length<8" @click="uploadZnImgs"
						style="width: 190rpx;height: 186rpx;background: #EDF6F5;border-radius: 8rpx;display: flex;flex-direction: column;align-items: center;justify-content: center;">
						<image src="../../static/images/pzp.png" style="width: 50%;" mode="widthFix"></image>
						<view>拍照</view>
					</view>
				</view>
			</view>
		</view>
		<view style="width: 100%;position: fixed;bottom: 40rpx;">
			<!-- <view class="add-btn" >向医生问诊</view> -->
			<button class="add-btn" @click="insertMessegOrder" :disabled="isCreate">向医生问诊</button>
			<view class="pt20 pb20 flex flex-ac ft11" style="padding-left: 40rpx;margin-top: 20rpx;">
				<radio-group @click="state=!state">
					<radio value="1" :checked="state" color="#2A82E4" />
				</radio-group>
				<text class="c999 ml15" style="margin-left: 0rpx;font-weight: bolder;">同意</text>
				<text class="c74a6fd ml5" @click="selectHopBook"
					style="color: #2A82E4;font-size: 24rpx;">邛崃民众门诊部患者知情同意书</text>
			</view>
		</view>
		<!-- 选择问诊目的 -->
		<view class="win flex flex-ac flex-pc" v-if="aimstate">
			<view class="ml25 mr25 w100 bgfff brund10">
				<view class="ft16 pt30 pb30 ftc">请选择问诊目的</view>
				<view class="rela aim">
					<view class="pt30 pb30 bb flex flex-ac flex-pj" @click.stop="aimkey=1">
						<view class="it1">
							<view class="ft16 bold">在线复诊</view>
							<view class="ft12 c999 mt20">针对复诊患者病情情况给出诊疗建议（可开具处方）</view>
						</view>
						<!-- <image v-if="aimkey==1" class="ycheck ml25" src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/check2y.png"></image>
						<view v-else class="ncheck box ml25"></view> -->
						<radio value="1" :checked="aimkey==1" style="transform:scale(0.8);color: #2A82E4;"
							color="#2A82E4" />
					</view>
					<view class="pt30 pb30 bb flex flex-ac flex-pj" @click.stop="aimkey=2">
						<view class="it1">
							<view class="ft16 bold">复诊续方</view>
							<view class="ft12 c999 mt20">针对复诊患者线上复诊以及再次复购药品</view>
						</view>
						<!-- <image v-if="aimkey==2" class="ycheck ml25" src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/check2y.png"></image>
						<view v-else class="ncheck box ml25"></view> -->
						<radio value="2" :checked="aimkey==2" style="transform:scale(0.8);color: #2A82E4;"
							color="#2A82E4" />
					</view>
					<view class="flex btnaum pt15 pb15 ft16">
						<text class="it1 ftc" @click="cancelaim">取消</text>
						<text class="c999 line"></text>
						<text class="it1 ftc c74a6fd" @click="confirmaim" style="color: #2A82E4;">确定</text>
					</view>
				</view>
			</view>
		</view>
		<view v-if='isSaveing'
			style="position: fixed;height: 100%;
			width: 100%;background-color: rgba(8, 8, 7, 0.5);z-index: 999;top:0rpx;left: 0rpx;display: flex;align-items: center;justify-content: center;">
			<icon type="waiting" size="26" />
			<text style="color: #FFFFFF;margin-left: 20rpx;font-size: 38rpx;">提交中...</text>
		</view>
		<!-- <view style="position: fixed;bottom: 150rpx;right: 50rpx;
			width: 120rpx;height: 120rpx;background: linear-gradient(0deg, #00BAAD, #81DCD6);
			box-shadow: 0px 0px 22rpx 2rpx rgba(162, 215, 211, 0.91);border-radius: 50%;
			display: flex;flex-direction: column;align-items: center;justify-content: center;z-index: 999;"
			@click="tohome">
			<image src="../../static/images/sy@2x.png" style="width: 50%;" mode="widthFix"></image>
			<view style="color: #FFFFFF;">首页</view>
		</view> -->
		<wyb-popup ref="popup" type="bottom" height="100" width="500" radius="2" :showCloseIcon="true">
			<view class="popup-content">
				<view class="part1">选择支付平台</view>
				<!-- 暂时 -->
				<!-- 	<view class="part2" @click="pay1">
					<image src="@/static/images/medical-logo.png" mode="" style="margin-left: 20rpx;"></image>
					<view class="" style="margin-left: 30rpx;">医保支付</view>
				</view> -->

				<view class="part3" @click="pay">
					<image src="@/static/images/wxzf.png" mode="" style="margin-left: 20rpx;"></image>
					<view class="" style="margin-left: 30rpx;">微信支付</view>
				</view>
			</view>
		</wyb-popup>

	</view>
</template>

<script>
	import wybPopup from '@/components/wyb-popup/wyb-popup.vue'
	export default {
		components: {
			wybPopup
		},
		data() {
			return {
				isCreate: false,
				hspName: '',
				wx: "https://app.mzmzb.com", //https://app.mzmzb.com   http://localhost:6110
				isNum: 2, //2:图文
				usrUserId: null,
				personalFileId: 0, //档案ID
				medDocInfoId: null, //医生ID
				consultant: null, //咨询人姓名

				sex: null, //咨询人姓名
				age: null, //咨询人姓名

				messagefee: null, //图文咨询费用
				adressInfo: 0, //收货地址
				medcalRecords: 0, //流水号

				chufangRecords: 0, //处方

				keyword: 0,
				state: false,
				current: 0,
				winstate: false,
				value: '',
				aimstate: false,
				aimkey: null,
				Imgs: [],
				znImgs: [],
				imgPaths: '',
				from: '',
				isSaveing: false, // 是否正在提交订单

				docUserId: null,
				docPhoto: null,
				docname: null,
				getthisid: null,
				GoDocId: null,
				price1: '',
				orderId1: '',
				imgLists: [],
				orderlist:[]
			};
		},
		onLoad(option) {
			if(option.orderlist){
				this.orderlist=JSON.parse(decodeURIComponent(option.orderlist))
			}
			var that = this;
			this.from = option.from;
			that.usrUserId = uni.getStorageSync('usrUserId')
			// that.medDocInfoId = uni.getStorageSync('medDocInfoId')
			this.docUserId = option.docUserId
			this.medDocInfoId = option.medDocInfoId
			this.docPhoto = option.docPhoto
			this.docname = option.docname
			that.messagefee = uni.getStorageSync('messagefee')
			// if (option.adressInfo == 'null' || option.adressInfo == 'undefined' || option.adressInfo == null) {
			// 	that.adressInfo = 0;
			// } else {
			// 	that.adressInfo = uni.getStorageSync("adressInfo");

			// }
			// if (option.medcalRecordId == undefined) {
			// 	that.medcalRecords = 0;
			// } else {
			// 	that.medcalRecords = uni.getStorageSync("medcalRecordId");
			// }
			that.aimkey = option.aimkey;
			that.keyword = uni.getStorageSync('keyInfo');
			that.state = uni.getStorageSync('state');
			// that.Imgs = uni.getStorageSync('imgs');
			console.log("图片:" + that.Imgs)
			console.log("用户ID:" + that.usrUserId)
			console.log("医生ID:" + that.medDocInfoId)
			console.log("图文咨询费用:" + that.messagefee)
			console.log("档案ID:" + that.personalFileId)
			console.log("咨询人姓名:" + that.consultant)
			console.log("收货地址:" + that.adressInfo)
			console.log("病历号:" + that.medcalRecords)
			console.log("诊疗选择:" + that.aimkey)
			uni.setStorageSync("isNum", that.isNum)
			uni.setStorageSync("adressInfo", that.adressInfo)
			uni.setStorageSync("medcalRecords", that.medcalRecords)
			uni.setStorageSync("aimkey", that.aimkey)

			this.getUserPersonalId()
		},
		onShow() {
			//查询订单状态
			setTimeout(() => {
				this.checkState()
			}, 100)
		},
		methods: {
			// getUserPersonalId() {
			// 	this.func.$request('wx/getUserPersonalId.tz', {
			// 		userId: this.usrUserId,
			// 		type: 1
			// 	}, 'GET').then(res => {
			// 		this.personalFileId = res.data.result.id
			// 		this.consultant = res.data.result.name
			// 		this.sex = res.data.result.sex
			// 		this.age = res.data.result.age / 12
			// 		this.age =Math.round(this.age)
			// 	})
			// },
			monthsToYearsAndMonths(months) {
				console.log(months, 999)
				let years = Math.floor(months / 12); // 计算完整的年数
				let remainingMonths = months % 12; // 计算剩余的月数
				let output = `${years}岁${remainingMonths}月`;
				console.log(output, 666)
				return output;
			},
			getUserPersonalId() {
				this.func.$request('wx/getUserPersonalId.tz', {
					userId: this.usrUserId,
					type: 1
				}, 'GET').then(res => {
					this.personalFileId = res.data.result.id
					this.consultant = res.data.result.name
					this.sex = res.data.result.sex
					this.age = this.monthsToYearsAndMonths(res.data.result.age)
					console.log(this.age)
				})

			},
			tohome() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			//选择咨询人
			toRecord() {
				var that = this;
				uni.navigateTo({
					url: '/pages/record/index?userId=' + that.usrUserId + '&medDocInfoId=' + that.medDocInfoId
				})
			},
			//跳转到收货地址首页
			toAddress() {
				uni.navigateTo({
					url: '/pages/address/index?userId=' + this.usrUserId + '&medDocInfoId=' + this.medDocInfoId
				})
			},
			toTitle() {
				uni.showToast({
					title: '请选择咨询人',
					icon: 'error'
				})
			},
			//跳转就诊记录首页
			toMedcalRecords() {
				//console.log('consultant===',this.consultant)
				if (this.consultant) {
					var that = this;
					uni.navigateTo({
						url: '/pages2/jiuzjl/index?userId=' + that.usrUserId + '&medDocInfoId=' + that
							.medDocInfoId +
							'&consultant=' + that.consultant + '&personalFileId=' + that.personalFileId +
							'&videofee=' + that.messagefee +
							'&adressInfo=' + that.adressInfo + '&aimkey=' + that.aimkey + '&isNum=' + that.isNum
					})
				} else {
					uni.showToast({
						title: '请选择咨询人',
						icon: 'error'
					})
				}
			},
			toChufangRecords() {
				if (this.consultant) {
					uni.navigateTo({
						url: '/pages3/chufang/index?userId=' + this.usrUserId + '&medDocInfoId=' +
							this.medDocInfoId + '&usrPersonalId=' + this.personalFileId +
							'&isChinOrder=0'
					})
				} else {
					uni.showToast({
						title: '请选择咨询人',
						icon: 'error'
					})
				}
			},
			//获取症状描述输入的值
			setKeyword(e) {
				this.keyword = e.detail.value
				console.log(this.keyword)
				uni.setStorage({
					key: 'keyInfo',
					data: this.keyword,
				})
			},
			delImg(val) {
				this.Imgs = this.Imgs.filter(item => item != val)
			},
			delZnImg(val) {
				this.znImgs = this.znImgs.filter(item => item != val)
			},
			uploadZnImgs() {
				this.uploadImg("zn")
			},
			uploadImg(typeParam) {
				let imglx = '_hangchu'
				if (typeParam == 'zn') {
					imglx = '_zhenliao'
				}
				var that = this
				uni.chooseImage({
					count: 9, // 默认9
					sizeType: ['original', 'camera'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: function(res) {
						uni.showLoading({
							title: '上传中...'
						});
						// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
						var tempFilePaths = res.tempFilePaths
						var myDate = new Date()
						var ossPath = 'ueditor/upload/weixin/' + myDate.getFullYear()
						var fileKeylist = []
						for (var i = 0; i < tempFilePaths.length; i++) {
							// 获取文件后缀
							//var pathArr = tempFilePaths[i].split('.')
							const imgsrc = res.tempFilePaths[i];
							const index = imgsrc.lastIndexOf(".");
							const imgExtension = imgsrc.substring(index + 1, imgsrc.length);
							console.log("后缀：" + imgExtension)
							//  随机生成文件名称
							var fileRandName = Date.now() + "" + parseInt(Math.random() * 1000)

							var fileName = fileRandName + imglx + '.' + imgExtension
							// 要提交的key
							var fileKey = ossPath + '/' + fileName

							fileKeylist.push(fileKey)
							uni.uploadFile({
								url: 'https://tuozhen1.oss-cn-beijing.aliyuncs.com/',
								filePath: tempFilePaths[i],
								name: 'file',
								formData: {
									name: tempFilePaths[i],
									key: fileKey,
									policy: 'eyJleHBpcmF0aW9uIjoiMjMzNy0wNC0xM1QwMjo0MjoxMi40ODFaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF0sWyJzdGFydHMtd2l0aCIsIiRrZXkiLCJ1ZWRpdG9yL3VwbG9hZC93ZWl4aW4vIl1dfQ==',
									OSSAccessKeyId: 'Te5npXFe8IdIxPgQ',
									signature: 'I1Dv3FioQ4hoBh0ui2Rvsax+fAI=',
									success_action_status: "200"
								},
								success: function(res) {
									console.log(res)
								}
							})
						}

						setTimeout(function() {
							that.getImgs(fileKeylist, imglx);
						}, 5000);
					}
				})
			},
			getImgs(e, it) {
				console.log(e)
				var that = this;
				// var imgLists = []
				// if (uni.getStorageSync('imgs').length != 0) {
				// 	for (var j = 0; j < uni.getStorageSync('imgs').length; j++) {
				// 		imgLists.push(uni.getStorageSync('imgs')[j])
				// 	}
				// }
				var Imgs = [...that.Imgs];
				var znImgs = [...that.znImgs];
				var imgLists = it == '_hangchu' ? Imgs : znImgs;
				if (uni.getStorageSync('imgs').length != 0) {
					for (var j = 0; j < uni.getStorageSync('imgs').length; j++) {
						imgLists.push(uni.getStorageSync('imgs')[j])
					}
				}
				for (var i = 0; i < e.length; i++) {
					var upliadImages = "http://tuozhen1.oss-cn-beijing.aliyuncs.com/" + e[i];
					console.log("携带的参数：" + upliadImages)
					imgLists.push(upliadImages);
				}
				uni.hideLoading()
				if (it == '_hangchu') {
					that.Imgs = imgLists
				} else {
					that.znImgs = imgLists
				}
				return
				uni.hideLoading()
				for (var i = 0; i < e.length; i++) {
					var upliadImages = e[i].path;
					console.log("携带的参数：" + upliadImages)
					if (e[i].type == '_hangchu') {
						console.log(1)
						that.Imgs.push(upliadImages)
						console.log(that.Imgs)
					} else {
						console.log(2)
						that.znImgs.push(upliadImages)
						console.log(that.znImgs)
					}
				}
				// if (it == '_hangchu') {
				// 	that.Imgs.push(upliadImages)
				// } else {
				// 	that.znImgs.push(upliadImages)
				// }
				// that.Imgs = imgLists
				// uni.setStorageSync('imgs', imgLists)
			},
			openwin() {
				this.winstate = !this.winstate;
			},
			setDate(e) {
				let state = e.currentTarget.dataset.state;
				if (state == 'before' && this.current > 0) {
					this.current = this.current - 1;
				} else if (state == 'after' && this.current < 2) {
					this.current = this.current + 1;
				}
			},
			choseTime(e) {
				this.value = e.currentTarget.dataset.value;
				this.openwin();
			},
			openaim() {
				this.aimstate = !this.aimstate;
			},
			confirmaim() {
				this.openaim();
			},
			cancelaim() {
				this.aimkey = null;
				this.openaim();
			},
			saveState() {
				var that = this
				that.state = !that.state;
				uni.setStorage({
					key: 'state',
					data: that.state
				})
			},
			selectHopBook() {
				uni.navigateTo({
					url: '/pages/agreement/index'
				})
			},


			pay1() {
				this.$refs.popup.close()
				var that = this;
				let aimkey = null
				var price = this.price1;
				var orderId = this.orderId1;
				let openId = uni.getStorageSync('openId')
				let data = {
					hspId: that.hspId,
					orderId: orderId,
					openId: openId,
				}
				that.func.$request('rczyywx/registerSettlement.tz', data, 'POST', 'application/x-www-form-urlencoded')
					.then(res => {
						wx.navigateToMiniProgram({
							appId: 'wx25ec5e985ebaacc7',
							path: 'pages/nativeLoading/index?webUrl=' + encodeURIComponent(res.data
								.errMsg),
							envVersion: 'trial'
						})
					})
				// uni.request({
				// 	url: 'https://app.mzmzb.com/application-usrapp/rczyywx/ycjgwx.tuozhen.com',
				// 	header: {
				// 		'content-type': 'application/x-www-form-urlencoded',
				// 	},
				// 	data: {
				// 		hspId: that.hspId,
				// 		orderId: orderId,
				// 		openId: openId,
				// 	},
				// 	method: "POST",
				// 	success: (res) => {
				// 		if (res.data.success) {
				// 			wx.navigateToMiniProgram({
				// 			appId: 'wx25ec5e985ebaacc7',
				// 			path: 'pages/nativeLoading/index?webUrl=' + encodeURIComponent(res.data
				// 				.errMsg),
				// 			// envVersion: 'trial',
				// 			envVersion: 'release'
				// 		})
				// 		} else {
				// 			uni.showToast({
				// 				title: res.data.errMsg,
				// 				icon: 'error'
				// 			})
				// 		}
				// 	}
				// })
			},

			getOrderId(orderId) {
				this.orderlist.forEach(e => {
					e.orderId = orderId
				})
				uni.request({
					url: `https://app.mzmzb.com/application-usrapp/zyf/saveZyfOrder.tz`,
					method: "GET",
					data: {
						dto: `{"orderList":` + JSON.stringify(this.orderlist) + `}`,
						userId: this.usrUserId
					},
					success(res) {
						console.log(res.data)
					}
				})
			},
			//提交图文咨询
			insertMessegOrder() {
				// this.isCreate=false
				if (this.isSaveing) {
					return
				}
				this.isSaveing = true
				if (this.isCreate) {
					return
				}
				this.isCreate = true

				var that = this;
				let aimkey = null;
				if (that.state == true) {
					if (that.personalFileId > 0) {
						if (that.adressInfo == 'null' || that.adressInfo == 'undefined' || that.adressInfo == null || that
							.adressInfo ==
							0) {
							uni.showToast({
								title: '请选择地址',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}
						if (that.aimkey == 'null' || that.aimkey == 'undefined' || that.aimkey == null) {
							uni.showToast({
								title: '请选择问诊目的',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}

						if (that.keyword == 'null' || that.keyword == 'undefined' || that.keyword == null || that
							.keyword == 0) {
							uni.showToast({
								title: '请输入症状描述',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}

						if (that.aimkey == 2 && (that.chufangRecords == 'null' ||
								that.chufangRecords == 'undefined' || that.chufangRecords == null || that.chufangRecords ==
								0)) {
							uni.showToast({
								title: '请选择历史处方',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}

						if (that.medcalRecords == 'null' || that.medcalRecords == 'undefined' || that.medcalRecords ==
							null || that.medcalRecords ==
							0) {
							that.medcalRecords = 0
						}

						// if (that.aimkey == 1 && that.medcalRecords == 0 // 在线复诊
						// 	&&
						// 	that.znImgs.length == 0) {
						// uni.showToast({
						// 	title: '请上传历史诊疗信息',
						// 	icon: 'error'
						// })
						// that.isSaveing = false
						// return
						// }

						console.log("medcalRecords4:" + that.medcalRecords)
						console.log("price:" + that.messagefee)
						console.log("medDocInfoId:" + that.medDocInfoId)
						console.log("usrPersonalFileId:" + that.personalFileId)
						console.log("address:" + that.adressInfo)
						console.log("problem:" + that.keyword)
						console.log("usrUserId:" + that.usrUserId)
						console.log("image:" + that.Imgs)

						if (that.aimkey == 1) {
							aimkey = 0
						}
						if (that.aimkey == 2) {
							aimkey = 1
						}
						// console.log("aimkey"+that.aimkey)
						// console.log("流水号1："+that.medcalRecords)
						//关闭弹窗
						if (this.isSaveing == true) {
							setTimeout(() => {
								this.isSaveing = false
							}, 1000)
							let imageArray = [].concat(that.Imgs).concat(that.znImgs)
							setTimeout(() => {
								if (that.medcalRecords == 0) {
									console.log("处方号2：" + that.chufangRecords)
									let url = 'userOrd/createWordsOrder.tz?usrUserId=' +
										that
										.usrUserId + '&price=' +
										that.messagefee + '&medDocInfoId=' + that.medDocInfoId +
										'&usrPersonalFileId=' + that.personalFileId + '&address=' +
										that
										.adressInfo +
										'&problem=' + that
										.keyword + '&image=' + imageArray + '&isContinuation=' +
										aimkey +
										'&historyRecipeId=' + that.chufangRecords + '&hspName=' + that
										.hspName
									that.func.$request(url, {}, 'POST', 'application/x-www-form-urlencoded',
										'WEIXIN').then(res => {

										console.log(res.data);
										that.getthisid = res.data.result.id
										that.GoDocId = res.data.result.usrUserId
										if (res.data.success == true) {
											var price = res.data.result.price;
											var orderId = res.data.result.id;
											if (that.orderlist.length > 0) {
												that.getOrderId(orderId)
											}
											this.price1 = price
											this.orderId1 = orderId

											//小王
											// that.func.$request('pay/tzPay.tz?money=' +
											// 		price +
											// 		'&remark=' +
											// 		orderId +
											// 		'&usrGetTypeEnum=user_word_expenditure' +
											// 		'&usrUserId=' + that.usrUserId +
											// 		'&thirdPayEnum=TzPay',{},'POST','application/x-www-form-urlencoded').then(item=>{
											// 			if (item.data.success) {
											// 				// that.isCreate=true
											// 				that.isSaveing = false
											// 				that.isCreate = false
											// 				that.sendMsg(orderId)
											// 				that.joinChat(orderId)
											// 			}
											// 		})

											if (price == 0) {
												that.func.$request('pay/tzPay.tz?money=' +
													price +
													'&remark=' +
													orderId +
													'&usrGetTypeEnum=user_word_expenditure' +
													'&usrUserId=' + that.usrUserId +
													'&thirdPayEnum=TzPay', {}, 'POST',
													'application/x-www-form-urlencoded').then(item => {
													if (item.data.success) {
														// that.isCreate=true
														that.isSaveing = false
														that.isCreate = false
														that.sendMsg(orderId)
														that.joinChat(orderId)
													}
												})
												return
											} else {
												that.$refs.popup.show()
											}
										} else {
											uni.showToast({
												title: res.data.errMsg,
												icon: 'error'
											})
										}
									})

								} else {
									that.medcalRecords = uni.getStorageSync("medcalRecordId")
									console.log("流水号3：" + that.medcalRecords)
									let url = 'userOrd/createWordsOrder.tz?usrUserId=' +
										that
										.usrUserId +
										'&medcalRecords=' +
										that.medcalRecords + '&price=' + that.messagefee +
										'&medDocInfoId=' +
										that
										.medDocInfoId +
										'&usrPersonalFileId=' + that.personalFileId + '&address=' +
										that
										.adressInfo +
										'&problem=' + that
										.keyword + '&image=' + imageArray + '&isContinuation=' +
										aimkey +
										'&hspName=' +
										that.hspName
									that.func.$request(url, {}, 'POST', 'application/x-www-form-urlencoded',
										'WEIXIN').then(res => {

										that.getthisid = res.data.result.id
										that.GoDocId = res.data.result.usrUserId
										var price = res.data.result.price;
										// 通联参数
										let parms = {
											id: res.data.result.id,
											medDocId: res.data.result.medDocInfoId,
											type: 0
										}
										if (res.data.success == true) {
											var orderId = res.data.result.id;
											if (that.orderlist.length > 0) {
												that.getOrderId(orderId)
											}
											that.price1 = price
											that.orderId1 = orderId
											//小王
											// that.func.$request('pay/tzPay.tz?money=' +
											// 		price +
											// 		'&remark=' +
											// 		orderId +
											// 		'&usrGetTypeEnum=user_word_expenditure' +
											// 		'&usrUserId=' + that.usrUserId +
											// 		'&thirdPayEnum=TzPay',{},'POST','application/x-www-form-urlencoded').then(item=>{
											// 			if (item.data.success) {
											// 				that.sendMsg(orderId)
											// 				that.joinChat(orderId)
											// 			}
											// 		})

											if (price == 0) {
												that.func.$request('pay/tzPay.tz?money=' +
													price +
													'&remark=' +
													orderId +
													'&usrGetTypeEnum=user_word_expenditure' +
													'&usrUserId=' + that.usrUserId +
													'&thirdPayEnum=TzPay', {}, 'POST',
													'application/x-www-form-urlencoded').then(item => {
													if (item.data.success) {
														that.sendMsg(orderId)
														that.joinChat(orderId)
													}
												})

												return
											} else {
												that.$refs.popup.show()
											}
										} else {
											uni.showToast({
												title: res.data.errMsg,
												icon: 'error'
											})
										}
									})

								}
							}, 1000)
							that.isClicking = false;
						}


					} else {
						that.isSaveing = false
						uni.showToast({
							title: '请选择咨询人',
							icon: 'error'
						})
						that.isCreate = false
					}

				} else {
					that.isSaveing = false
					uni.showToast({
						title: '请仔细阅读邛崃民众门诊部互联网患者知情同意书并勾选',
						icon: 'error'
					})
					that.isCreate = false
				}

			},

			pay() {
				this.$refs.popup.close()
				console.log('微希支付')
				// if (this.isSaveing) {
				// 	return
				// }
				// this.isSaveing = true
				// if (this.isCreate) {
				// 	return
				// }
				// this.isCreate = true
				// //关闭弹窗
				// if (this.isSaveing == true) {
				// 	setTimeout(() => {
				// 		this.isSaveing = false
				// 		this.isCreate = false
				// 	}, 2500)
				// }
				console.log('微希支付', 1)
				var that = this;
				if (that.personalFileId > 0) {
					let aimkey = null;
					if (that.state == true) {
						if (that.adressInfo == 'null' || that.adressInfo == 'undefined' || that.adressInfo == null || that
							.adressInfo ==
							0) {
							uni.showToast({
								title: '请选择地址',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}
						if (that.aimkey == 'null' || that.aimkey == 'undefined' || that.aimkey == null) {
							uni.showToast({
								title: '请选择问诊目的',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}

						if (that.keyword == 'null' || that.keyword == 'undefined' || that.keyword == null || that
							.keyword == 0) {
							uni.showToast({
								title: '请输入症状描述',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}

						if (that.aimkey == 2 && (that.chufangRecords == 'null' ||
								that.chufangRecords == 'undefined' || that.chufangRecords == null || that.chufangRecords ==
								0)) {
							uni.showToast({
								title: '请选择历史处方',
								icon: 'error'
							})
							that.isSaveing = false
							that.isCreate = false
							return
						}

						if (that.medcalRecords == 'null' || that.medcalRecords == 'undefined' || that.medcalRecords ==
							null || that.medcalRecords ==
							0) {
							that.medcalRecords = 0
						}

						if (that.aimkey == 1 && that.medcalRecords == 0 // 在线复诊
							&&
							that.znImgs.length == 0) {
							// uni.showToast({
							// 	title: '请上传历史诊疗信息',
							// 	icon: 'error'
							// })
							// that.isSaveing = false
							// return
						}

						if (that.aimkey == 1) {
							aimkey = 0
						}
						if (that.aimkey == 2) {
							aimkey = 1
						}
						console.log('微希支付', 2)
						let imageArray = [].concat(that.Imgs).concat(that.znImgs)
						var price = this.price1;
						var orderId = this.orderId1;
						uni.login({
							success: function(loginRes) {
								that.func.$request('wx/messegPay.tz?money=' +
									price + '&orderId=' +
									orderId +
									'&hspId=23840' +
									'&code=' + loginRes.code, {}, 'POST',
									'application/x-www-form-urlencoded').then(item => {

									if (item.data.success) {
										var timestamp = item.data
											.result.timeStamp;
										var nonceStr = item.data
											.result.nonceStr;
										var packages =
											'prepay_id=' + item
											.data.result.prepayid;
										var paySign = item.data
											.result.sign;
										uni.requestPayment({
											timeStamp: timestamp,
											nonceStr: nonceStr,
											package: packages,
											signType: 'MD5',
											paySign: paySign,
											success: function(
												res) {
												that.sendMsg(
													orderId
												)
												that.joinChat(
													orderId
												)
											},
											fail: function(
												err) {
												console
													.log(
														'fail:' +
														JSON
														.stringify(
															err
														)
													);
											}
										});
									} else {
										that.isSaveing = false
										that.isCreate = false
										that.warnMessage = item
											.data.errMsg;
										that.warnTime = 3000;
										that.$refs.popup.open();
									}
								}).catch(error => {
									that.isSaveing = false
									that.warnMessage = '支付失败';
									that.warnType = 'error';
									that.$refs.popup.open();
								})
							}
						});

					} else {
						that.isSaveing = false
						that.isCreate = false
						uni.showToast({
							title: '请选择咨询人',
							icon: 'error'
						})
					}

				} else {
					that.isCreate = false
					that.isSaveing = false
					uni.showToast({
						title: '请仔细阅读邛崃民众门诊部互联网患者知情同意书并勾选',
						icon: 'error'
					})
				}

			},



			//查询订单状态
			checkState() {
				var that = this
				that.func.$request('wx/getOrderPayState.tz', {
					orderId: this.getthisid
				}, 'GET', 'application/x-www-form-urlencoded').then(res => {
					if (res.data.result == 1) {
						uni.showToast({
							title: '支付成功',
							icon: 'none',
							duration: 2000
						})
						//跳转聊天i
						that.sendMsg(that.getthisid)
						that.joinChat(that.getthisid, that.GoDocId)
						return
					} else if (res.data.result == 0) {
						console.log('未支付');
						// uni.showToast({title: '未支付', icon: 'none',duration: 2000})
						return
					} else {
						uni.showToast({
							title: '支付失败',
							icon: 'none',
							duration: 2000
						})
					}
				})
			},

			sendMsg(orderId) {
				let avatarUrl = uni.getStorageSync("avatarUrl");
				let nickName = uni.getStorageSync("nickName");
				let from = uni.getStorageSync("usrUserId")
				let id = this.$im.conn.getUniqueId();
				let msg = new this.$im.message('txt', id);

				let extObj = {
					patientInfo: `${this.consultant} ${this.sex} ${this.age}`,
					problem: this.keyword,
					tcmQuestion: false,
					orderid: orderId,
					user_nickname: nickName,
					user_head: avatarUrl,
					user_id: from,
					messageType: 'txt',
					doctor_nickname: this.docname,
					doctor_id: this.medDocInfoId,
					doctor_head: this.docPhoto
				}

				let msgStr = ''
				if (this.aimkey == 2) {
					msgStr = '[请求续方]'
					extObj.selectRecipeId = this.chufangRecords
				} else {
					msgStr = '[问诊单]'
				}
				if (this.Imgs && this.Imgs.length > 0) {
					extObj.images = this.Imgs.join(',')
				}
				console.log('extObj===', extObj)
				msg.set({
					to: this.docUserId,
					from: from,
					msg: msgStr,
					roomType: false,
					chatType: 'singleChat',
					ext: extObj,
					success() {
						console.log('问诊通知成功了')
					},
					fail() {
						console.log('问诊通知失败了')
					}
				});
				this.$im.conn.send(msg.body);
			},
			//加入聊天
			joinChat(orderId) {
				let userId = uni.getStorageSync("usrUserId")
				let avatarUrl = uni.getStorageSync("avatarUrl");
				let nickName = uni.getStorageSync("nickName");
				var orderExt = {}; //发消息所需要的拓展数据
				orderExt.orderId = orderId;
				orderExt.messageType = '图文订单';
				orderExt.doctorId = this.docUserId;
				orderExt.doctorHead = this.docPhoto;
				orderExt.doctorNickname = this.docname;
				orderExt.userId = userId;
				orderExt.userHead = avatarUrl;
				orderExt.userNickname = nickName;
				orderExt.ordStatus = 1
				uni.redirectTo({
					url: '/pages/chatroom/chatroom?username=' + JSON.stringify(orderExt)
				});
			}
		}
	};
</script>

<style lang="less">
	.add-btn {
		margin: auto;
		height: 88rpx;
		line-height: 88rpx;
		width: 90%;
		background: #BE965B;
		border-radius: 44rpx;
		color: #FFFFFF;
		text-align: center;
	}

	.win {
		position: fixed;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		z-index: 100;
		background: rgba(0, 0, 0, 0.3);

		swiper {
			height: 450rpx;

			.arrow {
				width: 24rpx;
				height: 40rpx;
			}

			.date {
				line-height: 40rpx;
			}

			.arrowl {
				width: 10%;
				left: 0;
				padding-left: 15%;
				z-index: 100;
			}

			.arrowr {
				width: 10%;
				right: 0;
				padding-right: 15%;
				z-index: 100;
			}

			.time text {
				float: left;
				display: inline-block;
				width: 33.33%;
				line-height: 90rpx;
			}
		}

		.aim {
			padding: 0 50rpx;

			.ncheck {
				display: inline-block;
				width: 40rpx;
				height: 40rpx;
				border: 1rpx solid #EFEFEF;
			}

			.ycheck {
				width: 40rpx;
				height: 40rpx;
			}

			.btnaum {
				.line {
					width: 1rpx;
					background: #EFEFEF;
				}

				text {
					display: inline-block;
					height: 100rpx;
					line-height: 100rpx;
				}
			}
		}
	}

	textarea {
		height: 200rpx;
		border-radius: 5rpx;
		border: 1rpx solid #efefef;
	}

	.check2n {
		display: inline-block;
		width: 34rpx;
		height: 34rpx;
		border: 2rpx solid #838383;
	}

	.check2y {
		width: 24rpx;
		height: 24rpx;
	}

	.bottomBtn {
		margin-top: 30rpx;
		position: relative;
		height: 125rpx;
		width: 100%;

		.bottomBtncon {
			position: fixed;
			width: 700rpx;
			z-index: 10;
			left: 25rpx;
			height: 125rpx;
			bottom: 0;
			background: #FFFFFF;

			.btns {
				width: 660rpx;
				height: 100rpx;
				line-height: 100rpx;
				border-radius: 10rpx;
				background: #74a6fd;
			}
		}
	}

	.imgs {
		display: flex;

		image {
			width: 120rpx;
			height: 97rpx;
			margin: 10rpx;
		}
	}

	.part1 {
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
	}

	.imgs {
		display: flex;

		image {
			width: 120rpx;
			height: 97rpx;
			margin: 10rpx;
		}
	}

	.part2 {
		height: 100rpx;
		width: 96%;
		margin: 0 auto;
		border-bottom: 2rpx solid #ECECEC;
		display: flex;
		align-items: center;

		image {
			width: 70rpx;
			height: 30rpx;
		}
	}

	.part3 {
		height: 64rpx;
		width: 96%;
		margin: 0 auto;
		display: flex;
		align-items: center;
		border-bottom: 2rpx solid #ECECEC;

		image {
			width: 60rpx;
			height: 60rpx;
		}
	}
</style>